***************************************************************************************
***************************************************************************************
** Stata Code for Analyzing Data from AMOS 2012
** PROJECT: Revenue Source and Electoral Accountability: Experimental Evidence from Local U.S. Policymakers
** AUTHORS: Adam Dynes and Lucy Martin
** DATE: January 18, 2017
***************************************************************************************
***************************************************************************************  


clear all



use "dynes-martin_replication_AMOS2012.dta", clear


******************************************************************************************************************************
*****************************************************************************************************************************
// ANALYSIS
*****************************************************************************************************************************
*****************************************************************************************************************************

// DIRECT NON-EXPERIMENTAL QUESTION
	
	tab tvg_direct_1
	
	**Figure A-6: Responses to Non-Experimental Question on Revenue Source and Policy Incongruence (AMOS 2012)
		histogram tvg_direct_1,  discrete percent fcolor(ebblue) lcolor(eltblue) addlabel ylabel(0(5)30) xla(1/7, valuelabel noticks angle(45) labsize(small)) xtitle("Histogram of officials' agreement with" "the claim that there is more policy" "congruence with taxes than grants") aspect(.75) graphregion(color(white)) 
		graph export "direct_histogram.pdf", as(pdf) replace

	**Table A-3: Descriptive Statistics of Variables Used in Analysis of Responses to Non-Experimental Question on Revenue Source and Policy Incongruence (AMOS 2012)
		preserve
			gen insample=0
		
			qui reg tvg_direct_1 femalerd republican independent libcon mayor otherofficial tenure closevote unopposed unelected prog_amb_1  
		
			replace insample=1 if e(sample)
			keep if insample==1
			
			
			// List Variable Labels
			foreach var in femalerd republican independent democrat libcon mayor councilor commissioner otherofficial tenure closevote unopposed unelected prog_amb_1  homerulecharter   {
				di "`var'" _col(30) "`: var l `var''" _col(50)  "`: val l `var''"
			}
				
			foreach var in femalerd republican independent libcon mayor commissioner otherofficial tenure closevote unopposed unelected prog_amb_1    {
				di "`: var l `var''" _col(50)  "`: val l `var''"
				}
			
			estpost summarize femalerd republican independent democrat libcon mayor councilor commissioner otherofficial tenure closevote unopposed unelected prog_amb_1  homerulecharter, detail
				
		
			esttab, cells("mean sd p50 count min max") label
			drop insample
		restore	


	**Table A-4: Regression of Responses to Non-Experimental Question on Revenue Source and Policy Incongruence (AMOS 2012).
	**NOTE: These results are also the results from this question presented in Table A-24: Overall Results from Subgroup Analyses
		local outoptions label tex(frag) word se bdec(3) sdec(3) symbol(*,*)
		
		reg tvg_direct_1 femalerd republican independent libcon mayor otherofficial closevote unopposed unelected prog_amb_1  
		outreg2 using non-exp_OLS, replace `outoptions'
		

		reg tvg_direct_dum femalerd republican independent libcon mayor otherofficial tenure closevote unopposed unelected prog_amb_1  
		outreg2 using non-exp_OLS, append `outoptions'
		
		logit tvg_direct_dum femalerd republican independent libcon mayor otherofficial tenure closevote unopposed unelected prog_amb_1  
		outreg2 using non-exp_OLS, append `outoptions'
		


		
		


// ANALYSIS OF AGREE/DISAGREE QUESTIONS (TABLE 2)


	**TABLE 2: Revenue source and bottom-up accountability (AMOS 2012)
		foreach x of varlist minor_scandal nobid agreecare their_money agreemedia agreeseekinfo  {
			display "------------------> OUTCOME = `x' <------------------"
			ttest `x'_dum if elected==1, by(taxagree)
		}

	**Table A-10: Table 2 using the full 7-point scale	
		foreach x of varlist minor_scandal nobid agreecare their_money agreemedia agreeseekinfo  {
			display "------------------> OUTCOME = `x' <------------------"
			ttest `x' if elected==1, by(taxagree)
		}

	**Table A-11: Descriptive Statistics of Variables Used in Robustness Checks of Analysis from Table 2
		preserve
			keep if minor_scandal_dum<. | nobid_dum<. | agreemedia_dum<. | agreeseekinfo_dum<. | agreecare_dum<. | their_money_dum<. 
			
			gen insample=0
			
			foreach x in minor_scandal nobid agreecare their_money agreemedia agreeseekinfo {
				qui reg `x'_dum taxagree femalerd republican independent libcon mayor commissioner otherofficial tenure closevote unopposed unelected prog_amb_1  
				replace insample=1 if e(sample)
			}
			
			keep if insample==1
			
			
			estpost summarize femalerd republican independent democrat libcon mayor councilor commissioner otherofficial tenure closevote unopposed unelected prog_amb_1  homerulecharter, detail
			
			esttab, cells("mean sd p50 count min max") label
		restore

	**Table A-12: Regression Results for Table 2 with Control Variables
		local intercontrols femalerd republican independent libcon mayor otherofficial tenure closevote unopposed unelected prog_amb_1  
	
		reg minor_scandal_dum taxagree `intercontrols'
			outreg2 using Table2_Agree_Disagree_OLSdum_controls, replace `outoptions'
		
		foreach x in nobid agreecare their_money agreemedia agreeseekinfo   {
			reg `x'_dum taxagree `intercontrols'
			outreg2 using Table2_Agree_Disagree_OLSdum_controls, append `outoptions'		
			}
			
	**Table A-13: Regression Results for Table 2 with Control Variables using Logit			
		logit minor_scandal_dum taxagree `intercontrols'
			outreg2 using Table2_Agree_Disagree_logdum_controls, replace `outoptions'
		
		foreach x in nobid agreecare their_money agreemedia agreeseekinfo   {
			logit `x'_dum taxagree `intercontrols'
			outreg2 using Table2_Agree_Disagree_logdum_controls, append `outoptions'		
			}
			
	**Table A-14: Regression Results for Table 2 with Control Variables and 7-point Outcome
		reg minor_scandal_0 taxagree `intercontrols'
			outreg2 using Table2_Agree_Disagree_OLS0_controls, replace `outoptions'
		
		foreach x in nobid agreecare their_money agreemedia agreeseekinfo   {
			reg `x'_0 taxagree `intercontrols'
			outreg2 using Table2_Agree_Disagree_OLS0_controls, append `outoptions'		
			}	


	**Table A-28:Testing for Heterogeneous Treatment Effects from  Table 2 withIndividual-Level Variables.
		
		reg minor_scandal_dum taxagree independent republican taXindependent taXrepublican `intercontrols'
		regsave taxagree independent republican taXindependent taXrepublican using subgroup_interactions_table2.dta, ci pval  addlabel(table, 2, interaction, party, outcome, minor_scandal) replace
		reg minor_scandal_dum taxagree independent republican taXindependent taXrepublican 	
		regsave taxagree independent republican taXindependent taXrepublican using subgroup_interactions_table2_nocontrols.dta, ci pval  addlabel(table, 2, interaction, party, outcome, minor_scandal) replace

		foreach y in nobid agreecare their_money agreemedia agreeseekinfo {
			reg `y'_dum taxagree independent republican taXindependent taXrepublican `intercontrols'
			regsave taxagree independent republican taXindependent taXrepublican using subgroup_interactions_table2.dta, ci pval  addlabel(table, 2, interaction, party, outcome, `y') append
			reg `y'_dum taxagree independent republican taXindependent taXrepublican
			regsave taxagree independent republican taXindependent taXrepublican using subgroup_interactions_table2_nocontrols.dta, ci pval  addlabel(table, 2, interaction, party, outcome, `y') append
		}
		
		foreach y in minor_scandal nobid agreecare their_money agreemedia agreeseekinfo {
			reg `y'_dum taxagree mayor otherofficial taXmayor taXcommissioner taXotherofficial `intercontrols'
			regsave taxagree mayor otherofficial taXmayor taXcommissioner taXotherofficial using subgroup_interactions_table2.dta, ci pval  addlabel(table, 2, interaction, position, outcome, `y') append
			reg `y'_dum taxagree mayor otherofficial taXmayor taXcommissioner taXotherofficial
			regsave taxagree mayor otherofficial taXmayor  taXotherofficial using subgroup_interactions_table2_nocontrols.dta, ci pval  addlabel(table, 2, interaction, position, outcome, `y') append
		}
		
		
		foreach x in femalerd libcon closevote unopposed unelected tenure prog_amb_1 {
			foreach y in minor_scandal nobid agreecare their_money agreemedia agreeseekinfo {
				reg `y'_dum taxagree `x' taX`x' `intercontrols'
				regsave taxagree `x' taX`x' using subgroup_interactions_table2.dta, ci pval  addlabel(table, 2, interaction, `x', outcome, `y') append
				reg `y'_dum taxagree `x' taX`x'
				regsave taxagree `x' taX`x' using subgroup_interactions_table2_nocontrols.dta, ci pval  addlabel(table, 2, interaction, `x', outcome, `y') append
			}
		}
	
		foreach name in table2 table2_nocontrols {
		preserve
			clear
			use "subgroup_interactions_`name'.dta"
			keep if regexm(var, "taX")
			keep var coef stderr pval outcome
			replace coef = round(coef,.001)
			replace stderr = round(stderr,.001)
			replace pval = round(pval,.001)
			gen order1=.
			replace order1=1 if outcome=="minor_scandal"
			replace order1=2 if outcome=="nobid"
			replace order1=3 if outcome=="agreecare"
			replace order1=4 if outcome=="their_money"
			replace order1=5 if outcome=="agreemedia"
			replace order1=6 if outcome=="agreeseekinfo"
			sort var order1

			rename coef est_coef
			rename stderr est_stderr
			reshape long est_, i(var outcome order pval) j(type) string
			rename est_ estimate
			gen order2=.
			replace order2=1 if type=="coef"
			replace order2=2 if type=="stderr"
			sort var order1 order2
			drop outcome type
			order estimate, before(pval)
			reshape wide estimate pval, i(var order2) j(order1)
			rename estimate1 Scandal
			rename estimate2 No_Bid
			rename estimate3 Care
			rename estimate4 Theirs
			rename estimate5 Media
			rename estimate6 Seek_Info
			foreach num of numlist 1/6 {
				replace pval`num'=. if order2==1
			}
			rename pval1 Scandal_pval
			rename pval2 No_Bid_pval
			rename pval3 Care_pval
			rename pval4 Theirs_pval
			rename pval5 Media_pval
			rename pval6 Seek_Info_pval 
			order order2, first
			gen order1=.
			
			replace order1=1 if var=="taXfemalerd"
			replace order1=2 if var=="taXrepublican"
			replace order1=3 if var=="taXindependent"
			replace order1=4 if var=="taXlibcon"
			replace order1=5 if var=="taXmayor"
			replace order1=6 if var=="taXcommissioner"
			replace order1=7 if var=="taXotherofficial"
			replace order1=8 if var=="taXtenure"			
			replace order1=9 if var=="taXclosevote"
			replace order1=10 if var=="taXunopposed"
			replace order1=11 if var=="taXunelected"
			replace order1=12 if var=="taXprog_amb_1"


			
			order order1, first
			sort order1 order2
			replace var="Female (1=yes)" if var=="taXfemalerd"
			replace var="Republican (1=yes)" if var=="taXrepublican"
			replace var="Independent (1=yes)" if var=="taXindependent"
			replace var="Self-Placed Ideology (7-pt., 1=Very Liberal)" if var=="taXlibcon"
			replace var="Mayor (1=yes)" if var=="taXmayor"
			replace var="Commissioner or Supervisor (1=yes)" if var=="taXcommissioner"
			replace var="Other Official (1=yes)" if var=="taXotherofficial"
			replace var="Tenure: Years Served in Current Office" if var=="taXtenure"
			replace var="Close Election: Has had election w/ vote margin of 5% pts. or less (1=yes)" if var=="taXclosevote"
			replace var="Unelected Official (1=yes)" if var=="taXunelected"
			replace var="Unopposed: Never Contested in an Election (1=yes)" if var=="taXunopposed"
			replace var="Ambition: Prob. will run for higher office in 5 yrs." if var=="taXprog_amb_1"
			replace var="Partisan Elections (1=yes)" if var==""
			replace var="Mayoral Form of Gov't (1=yes)" if var==""
			replace var="Commissioner Form of Gov't (1=yes)" if var==""
			replace var="Town Meeting Based Policy (1=yes)" if var==""
			replace var="Home Rule Charter (1=yes)" if var==""
			
			compress
			save "subgroup_interactions_`name'_clean.dta", replace
		restore
		}
		


